Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move log4j-api to correct quarkus module and add condition for jackson-module-jaxb-annotations registrations #30018

Conversation

zakkak
Copy link
Contributor

@zakkak zakkak commented Dec 21, 2022

log4j-api is a dependency of elasticsearch-rest-high-level-client

log4j-api is not always present when using the
elasticsearch-rest-client-common extension as it's not a dependency of
it. Instead, it is a dependency of elasticsearch-rest-high-level-client:

+- io.quarkus:quarkus-elasticsearch-rest-high-level-client:jar:999-SNAPSHOT:compile
|  +- ...
|  +- org.jboss.logmanager:log4j2-jboss-logmanager:jar:1.1.1.Final:compile
|  |  \- org.apache.logging.log4j:log4j-api:jar:2.19.0:compile

com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector is not
always present when using the quarkus-jackson extension as it's not a
dependency of it. Instead, it is a dependency of
quarkus-resteasy-jackson:

+- io.quarkus:quarkus-resteasy-jackson:jar:999-SNAPSHOT:compile
|  +- ...
|  +- org.jboss.resteasy:resteasy-jackson2-provider:jar:4.7.7.Final:compile
|  |  +- ...
|  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.14.1:compile
|  |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.14.1:compile
|  |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.14.1:compile

This results in failed attempts to register the class for reflection
when using the quarkus-jackson extension without
jackson-module-jaxb-annotations in the classpath.

Since we expect users to manually include the artifact in their
dependencies even when not using quarkus-resteasy-jackson we maintain
the registration in the quarkus-jackson extension but only perform it
when the artifact is present in the classpath.

cc @essobedo

Fixes warnings appearing with #29886

@quarkus-bot quarkus-bot bot added area/elasticsearch area/jackson Issues related to Jackson (JSON library) labels Dec 21, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 21, 2022

/cc @gsmet(elasticsearch), @loicmathieu(elasticsearch), @yrodiere(elasticsearch)

@quarkus-bot

This comment has been minimized.


@BuildStep
ReflectiveClassBuildItem register() {
return new ReflectiveClassBuildItem(true, false, "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO Jackson stuff should be managed by the Jackson extension, which makes more sense here as resteasy-jackson depends on jackson.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory I agree, but the thing is that the jackson extension does not depend on com.fasterxml.jackson.module:jackson-module-jaxb-annotations so there seems no need for it to register classes in it. On the other hand, resteasy-jackson does depend on com.fasterxml.jackson.module:jackson-module-jaxb-annotations (and is the reason we need to register the classes for reflection) so in practice it makes sense to me to move the registration there unless we expect people to manually add com.fasterxml.jackson.module:jackson-module-jaxb-annotations as a depedency to their project and assume that using quarkus-jackson would suffice to support it.

The Quarkus team should have better insight on this than me, since they probably have a better picture of how these extensions are used in the wild.

The alternative here is to keep the registration in quarkus-jackson and only perform it when com.fasterxml.jackson.module:jackson-module-jaxb-annotations is in the classpath.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the Elasticsearch part.

I'm less sure about the Jackson part, since it's entirely possible that another extension makes use of jackson-module-jaxb-annotations without using RestEasy. Ideally we'd have a quarkus-jackson-jaxb-annotations extension, but that kind of strategy obviously cannot scale. I'd be in favor of not applying this change (the Jackson part) and instead finding some way of supressing warnings when we know they are not problematic, but I'll let more knowledgeable people decide.

@zakkak
Copy link
Contributor Author

zakkak commented Dec 22, 2022

I'd be in favor of not applying this change (the Jackson part) and instead finding some way of supressing warnings when we know they are not problematic, but I'll let more knowledgeable people decide.

As said in #30018 (comment):

The alternative here is to keep the registration in quarkus-jackson and only perform it when com.fasterxml.jackson.module:jackson-module-jaxb-annotations is in the classpath.

Happy to proceed this way if there is consensus.

@geoand
Copy link
Contributor

geoand commented Dec 23, 2022

The alternative here is to keep the registration in quarkus-jackson and only perform it when com.fasterxml.jackson.module:jackson-module-jaxb-annotations is in the classpath.

Happy to proceed this way if there is consensus.

+1

log4j-api is a dependency of elasticsearch-rest-high-level-client

`log4j-api` is not always present when using the
elasticsearch-rest-client-common extension as it's not a dependency of
it. Instead, it is a dependency of elasticsearch-rest-high-level-client:

```
+- io.quarkus:quarkus-elasticsearch-rest-high-level-client:jar:999-SNAPSHOT:compile
|  +- ...
|  +- org.jboss.logmanager:log4j2-jboss-logmanager:jar:1.1.1.Final:compile
|  |  \- org.apache.logging.log4j:log4j-api:jar:2.19.0:compile
```

`com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector` is not
always present when using the quarkus-jackson extension as it's not a
dependency of it. Instead, it is a dependency of
quarkus-resteasy-jackson:

```
+- io.quarkus:quarkus-resteasy-jackson:jar:999-SNAPSHOT:compile
|  +- ...
|  +- org.jboss.resteasy:resteasy-jackson2-provider:jar:4.7.7.Final:compile
|  |  +- ...
|  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.14.1:compile
|  |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.14.1:compile
|  |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.14.1:compile
```

This results in failed attempts to register the class for reflection
when using the `quarkus-jackson` extension without
`jackson-module-jaxb-annotations` in the classpath.

Since we expect users to manually include the artifact in their
dependencies even when not using `quarkus-resteasy-jackson` we maintain
the registration in the `quarkus-jackson` extension but only perform it
when the artifact is present in the classpath.
@zakkak zakkak force-pushed the 2022-12-21-move-registrations-to-proper-extensions branch from c5009f1 to 690eeaf Compare December 23, 2022 16:21
@zakkak zakkak changed the title Move log4j-api and jackson-module-jaxb-annotations registrations to correct quarkus modules Move log4j-api to correct quarkus module and add condition for jackson-module-jaxb-annotations registrations Dec 23, 2022
@zakkak
Copy link
Contributor Author

zakkak commented Dec 23, 2022

I updated the jackson changes based on the provided feedback, please re-review.

@zakkak zakkak requested review from essobedo and yrodiere and removed request for essobedo December 23, 2022 16:23
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 24, 2022

Failing Jobs - Building 690eeaf

Status Name Step Failures Logs Raw logs
✔️ JVM Tests - JDK 11
✔️ JVM Tests - JDK 17
JVM Tests - JDK 17 MacOS M1 Build ⚠️ Check → Logs Raw logs
✔️ JVM Tests - JDK 18

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the Elasticsearch part, no change, LGTM.

Regarding the Jackson part, personally I would very much prefer to fix #29886 so that there's no warning when a class enabled for reflection is not found, be it only when we enable a "nowarning" flag on ReflectiveClassBuildItem. Because I very much doubt we will want to jump through hoops like this every time we need to handle an optional dependency.

But if this solution is what @geoand prefers... I'll let @geoand approve ;)

@yrodiere yrodiere requested a review from geoand January 2, 2023 08:10
Comment on lines +131 to +132
x -> x.getGroupId().equals("com.fasterxml.jackson.module")
&& x.getArtifactId().equals("jackson-module-jaxb-annotations"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I've asked elsewhere too so apologies for that, but did we reach a consensus about this pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is no better way at the moment (see #29886 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@zakkak
Copy link
Contributor Author

zakkak commented Jan 3, 2023

Thank for the (re-)review @yrodiere

prefer to fix #29886 so that there's no warning when a class enabled for reflection is not found

IMHO that would not be a fix, but instead it would mean maintaining an old issue. I personally prefer having someone manually going through such errors and jumping through hooks from having classes that should be registered, not being registered without anyone noticing.

@yrodiere yrodiere merged commit 533f315 into quarkusio:main Jan 3, 2023
@quarkus-bot quarkus-bot bot added this to the 2.16 - main milestone Jan 3, 2023
@zakkak zakkak deleted the 2022-12-21-move-registrations-to-proper-extensions branch January 3, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/elasticsearch area/jackson Issues related to Jackson (JSON library) area/native-image
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants